<?php

/**
 * Created by PhpStorm.
 * User: IsSwm
 * Date: 2017/6/21
 * Time: 15:57
 */

namespace app\product\controller;

use think\Controller;

class Product extends Controller
{

    //小程序
    public function index($type_id = 0, $offset = 0, $pagesize = 4)
    {

        $type_id = intval($type_id);
        //排序方向
        switch ($type_id) {
            case 1:
                $orderField = "id";
                $orderOrder = "ASC";
                break;
            case 2:
                $orderField = "price";
                $orderOrder = "DESC";
                break;
            case 3:
                $orderField = "score";
                $orderOrder = "DESC";
                break;
            case 4:
                $orderField = "clicks";
                $orderOrder = "DESC";
                break;
            default:
                $orderField = "id";
                $orderOrder = "DESC";
                break;
        }

        $product = db('product')->where('status', '0')->order($orderField, $orderOrder)->limit($offset, $pagesize)->select();
        if ($product) {
            foreach ($product as $k => $value) {
                $product[$k]['detail'] =
                    strip_tags($value['detail']);
                $product[$k]['add_time'] = date('y-m-d', $value['add_time']);
            }
        }
        return $this->sucReturn($product);
    }
}
